/*
 * loginScreen.fx
 *
 * Created on 18 nov. 2009, 21:48:41
 */

package start;
import javafx.io.Resource;
import javafx.io.Storage;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.Label;
import javafx.scene.control.TextBox;
import java.lang.*;
import javafx.scene.Scene;

import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.scene.control.Button;
import javafx.util.Properties;

/**
 * @author esp
 */


var vSep:Number =40;
var hSep:Number = 30;
var hSep_2:Number = bind hSep * 5 ;
var hSep_3_links:Number = bind hSep_2 + 50;



//verandelijke voor wanner de gebruiker zich inlogt
var email:String;
var password:String;


// voor onthoudOpPC
//zie screencast : JavaFX/fx00_23_00_Storage/fx00_23_00_Storage_controller.swf
var entry:Storage = Storage{source : "user.prop"}
var resource: Resource = entry.resource;


    var labelEmail:Label=Label {
        layoutX: hSep
        layoutY: vSep
	text: "Email Adres"
}
    var labelPasswd: Label=Label {
        layoutX: hSep
        layoutY: vSep * 2
	text: "Wachtwoord"
}
    var linkPassVergeten:Hyperlink = Hyperlink {

        translateX: hSep
        translateY: vSep * 3
        text: "Password vergeten?"
	action: function() {
            }
}


    var onthoudOpPc: CheckBox=CheckBox {
       layoutX: hSep
        layoutY: (vSep * 4) 
	text: "Onthoud op Pc "
	allowTriState: false
	selected: false
 }

    var txtBoxEmail:TextBox = TextBox {

        layoutX:hSep_2
        layoutY: vSep
	text: ""
	columns: 20
	selectOnFocus: true
}
    var txtBoxPasswd:PasswordBox = PasswordBox {
        layoutX:hSep_2
        layoutY: vSep * 2
	text: ""
	columns: 20
	selectOnFocus: true
 }


    var buttConnection:Button=Button {
        layoutX:hSep
        layoutY:vSep * 5
	text: "Sign In"
	action: function() {

            var email:String;
            var password:String;
            email = txtBoxEmail.text;
            password = txtBoxPasswd.text;

            if(not email.trim().equalsIgnoreCase("") and not password.trim().equalsIgnoreCase("")){
                  var ok:Boolean = performLogin(email, password);

                   if(ok){

                       //TODO
                   }
            }

	}
 }

    var buttInschrijving:Button=Button {
        layoutX:hSep_2
        layoutY:vSep * 5
	text: "Niewe gebruiker"
	action: function() {
         
            /*
            var up:UploadCast = new UploadCast();
            up.createCastBrowser();

            var file:String;
            file = up.browseUpload();
            if(file != null )
             System.out.println(file);

             */
	}
 }

   var linkNewCasts:Hyperlink = Hyperlink {

        layoutX:hSep
        layoutY:vSep * 7
        text: "My new casts "
	action: function() {
           }
}
 
   var linkUploadCasts:Hyperlink = Hyperlink {

        layoutX:hSep
        layoutY:vSep * 8
        text: "Upload new screenast "
	action: function() {
                //TODO
            }
}

   var linkBeheerUsers:Hyperlink = Hyperlink {

          layoutX:hSep
        layoutY:vSep * 9
        text: "Zoek screencasts "
	action: function() {
        }
}


  var linkMailUsers:Hyperlink = Hyperlink {


        layoutX:hSep
        layoutY:vSep * 10
        text: "Mail users geselecteerd by tags "
	action: function() {
        }
}

  var linkLastViewedCasts:Hyperlink = Hyperlink {
        layoutX:hSep_3_links
        layoutY: vSep * 7
        text: "LastViewedCassts "
	action: function() {
        }
}

  var linkRapporten:Hyperlink = Hyperlink {

        layoutX:hSep_3_links
        layoutY: vSep * 8
        text: "Rapporten"
	action: function() {
        }
}

  var linkMostViewedPublic:Hyperlink = Hyperlink {

        layoutX:hSep_3_links
        layoutY: vSep * 9
        text: "Most Viewed Public"
	action: function() {
        }
}

  var linkBatchEnroll:Hyperlink = Hyperlink {

        layoutX:hSep
        layoutY: vSep * 11
        text: "Batch Enroll"
	action: function() {
        }
}

//TODO : implement
function performLogin(email:String, password:String):Boolean {



    //TODO : Check if email and password correct before



    if(onthoudOpPc.selected){

            var outStream = resource.openOutputStream(true);
            var prop = Properties{};
            prop.put("email",email);
            prop.put("passwd",password);
            prop.store(outStream);
            outStream.close();
        
    }
    return true;
}
//TODO : implement
function nieuweGebruiker(){

    var sc:Scene;
    var st:Stage;

}


//// !!! Maken een klasse Login Screen extends Scene, waarin de nodes ( texBox,enz. ) gedefinieerd zijn 
 var loginScene:Scene=Scene {
        width: 380
        height: 500
	content: [
            labelEmail,
            labelPasswd,
            linkPassVergeten,
            onthoudOpPc,
            buttInschrijving,
            buttConnection,
            txtBoxEmail,
            txtBoxPasswd,
            linkBatchEnroll,
            linkBeheerUsers,
            linkLastViewedCasts,
            linkMailUsers,
            linkMostViewedPublic,
            linkNewCasts,
            linkRapporten,
            linkUploadCasts
        ]
        fill: Color.LIGHTGRAY;
}


Stage {
    title: "Login"
    scene: loginScene
}



